/*
 PureMVC AS3 Demo - Flex CafeTownsend
 Copyright (c) 2007-08 Michael Ramirez <michael.ramirez@puremvc.org>
 Parts Copyright (c) 2005-07 Adobe Systems, Inc. 
 Your reuse is governed by the Creative Commons Attribution 3.0 License
 */
package org.puremvc.as3.demos.flex.cafetownsend.model
{
	import com.salesforce.AsyncResponder;
	import com.salesforce.Connection;
	import com.salesforce.objects.LoginRequest;
	import com.salesforce.results.LoginResult;
	import com.salesforce.results.QueryResult;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.puremvc.as3.demos.flex.cafetownsend.ApplicationFacade;
	import org.puremvc.as3.demos.flex.cafetownsend.model.vo.User;
	import org.puremvc.as3.demos.flex.cafetownsend.view.components.EmployeeList;
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.Mediator;
	import org.puremvc.as3.patterns.proxy.Proxy;
    
    /**
     * A proxy for the User data
     */
    public class UserProxy extends Proxy implements IProxy
    {
		public static const NAME:String = "UserProxy";
		public static const VIEW_EMPLOYEE_LIST:String = "viewEmployeeList";
		
		private var force:Connection = new Connection();
		
		[Bindable]
		public var cList:ArrayCollection = new ArrayCollection();

		public function UserProxy ( data:Object = null ) 
        {
            super ( NAME, data );
        }
		
		public function validate( username:String, password:String ):Boolean
		{
			if( username != null && password != null )
			{
				
				/*var lr:LoginRequest = new LoginRequest();
				lr.username = username;
				lr.password = password+"vig0Bol58W1jjYzZytraZr8y8";
				lr.callback = new AsyncResponder(loginSuccess);
				force.login(lr);*/
				//data = new User(username,password);
				return true;
			}
			else
			{
				return false;
			}
		}
		
		/*private function loginSuccess(result:LoginResult):void
		{
			Alert.show("Login Success");
			force.query("SELECT CreatedDate,Email,FirstName,LastName FROM Contact", new AsyncResponder(queryResult));
		}
		
		public function queryResult(result:QueryResult):void{
			cList = result.records;
			Alert.show("Contacts List size:"+result.size.toString());
			sendNotification(ApplicationFacade.VIEW_EMPLOYEE_LIST);
			//sendNotification(ApplicationFacade.VIEW_EMPLOYEE_DETAIL);
		}*/
		
		public function get user():User
		{
			return data as User;
		}
		
		

	}
}